package com.example.producer.produce;

import com.alibaba.fastjson.JSON;
import com.example.producer.entity.Order;
import org.springframework.amqp.core.MessageProperties;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.rabbit.support.CorrelationData;
import org.springframework.amqp.support.converter.AbstractJavaTypeMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageHeaders;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Component;

import java.util.HashMap;

/**
 * Delay Queue第一种实现方式: ttl+ dlx
 *
 * @author shuc001
 * @Date 2018/9/27 下午4:26
 */
@Component
public class DelaySend1 {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    public void send(Order order){

        rabbitTemplate.convertAndSend("ttl_ex","ttl.#",JSON.toJSONString(order),message -> {
            //message.getMessageProperties().setHeader(AbstractJavaTypeMapper.DEFAULT_CONTENT_CLASSID_FIELD_NAME,"com.example.consumer.entity.Order");
            message.getMessageProperties().setExpiration("5000");
            return message;
        },new CorrelationData(order.getId()));
    }
}
